package com.boarsoft.boar.config.lock.biz.impl;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boarsoft.boar.config.lock.LockListener;
import com.boarsoft.boar.config.lock.biz.LockListenerBiz;
import com.boarsoft.common.Util;
import com.boarsoft.hibernate.biz.SimpleBizImpl;

@Component
public class LockListenerBizImpl extends SimpleBizImpl implements LockListenerBiz {
    @Transactional
    @Override
    public void save(LockListener lockListene) {
        if (Util.strIsEmpty(lockListene.getId())) {
            this.dao.save(lockListene);
        } else {
            this.dao.merge(lockListene);
        }
    }
    @Transactional
    @Override
    public void delete(LockListener lockListener) {
        this.dao.delete(lockListener);
    }

    @Transactional(
            readOnly = true
    )
    @Override
    public List<LockListener> find(String url, String appId, String type) {
        StringBuilder sb = new StringBuilder();
        if (Util.strIsNotEmpty(appId)) {
            sb.append(" and vAppId = '").append(appId).append("'");
        }
        if (Util.strIsNotEmpty(url)) {
            sb.append(" and vUrl = '").append(url).append("'");
        }
        if (Util.strIsNotEmpty(type)) {
            sb.append(" and vType = '").append(type).append("'");
        }
        sb.append(" order by cId");
        return this.dao.list(LockListener.class,sb.toString());
    }
}
